package com.breeze.utils;

import java.util.LinkedList;
import java.util.Queue;

public class TreeUtils {
    // 层序遍历
    public static void showLevelOrder(TreeNode head) {
        if (head == null) {
            return;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(head);
        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();
            System.out.print(node.val + ",");
            if (node.left != null) {
                queue.offer(node.left);
            }
            if (node.right != null) {
                queue.offer(node.right);
            }
        }
    }

    public static void showPostOrder(TreeNode head) {
        if (head == null) {
            return;
        }
        showPostOrder(head.left);
        showPostOrder(head.right);
        System.out.print(head.val + ",");
    }
}
